<?php


namespace Frieza\Modules\Position\Controllers;

use Doraemon\model\Position\PositionExtend;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;

class KeywordSearchController extends BaseController
{
    use BaseTrait;

    public $base_field_pos = 1;
    public function beforeTitleForm(Form $form)
    {
        $form->radio('base.pos', '高亮显示')->options(['1'=> '是', '0' => '否'])->required();
        $form->text('key_word', '关键词')->required();
        $form->multiLinkSelect('base.link', '内容', [])->help('支持整屋案例');
    }

    public function saveModule(Request $request, $baseInfoId)
    {
        $key_word = $request->input('key_word', '');
        PositionExtend::saveSearchResultBanner($baseInfoId, $key_word);
    }

    public function extendDefaultBaseInfo()
    {
        return [
            'key_word' => $this->relation['ad_unique'] ?? ''
        ];
    }

    public function extendList(Grid $grid)
    {
        $grid->column('ext->key_word', '关键词')->label();
        $grid->column('pos', '是否高亮')->display(function ($title, Grid\Column $column) {
            return $this->pos == 1 ? "高亮" : "普通";
        });
    }
}
